package datasource

import (
	"alarm-flow/config"
	"context"
	"fmt"
	"github.com/redis/go-redis/v9"
)

var RedisCli *redis.Client

func InitRedis(config config.Redis) (err error) {

	passwd, err := config.CleanPwd()
	if err != nil {
		return
	}

	RedisCli = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%d", config.Host, config.Port),
		Password: passwd,
		DB:       config.Database,
	})

	return RedisCli.Ping(context.Background()).Err()
}
